import time

from appium import webdriver
from functools import wraps


def singleton(cls):
    """单例类装饰器"""
    instances = {}

    @wraps(cls)
    def wrapper(*args, **kwargs):
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]

    return wrapper


@singleton
class Driver():
    def __new__(cls, *args, **kwargs):
        cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723/wd/hub',
                                      desired_capabilities={
                                          'platformName': 'Android',
                                          # 'appPackage':'com.sykean.biometrics',
                                          # 'appActivity':'.activity.IdentificationActivity'
                                      })
        cls.driver.implicitly_wait(5)

        return cls.driver


if __name__ == '__main__':
    driver = Driver()


